Adding some more judges, here and there.
[and.git] / lib / Mi manual de algoritmos / version_actual / src / geometria / circle_through_3_points.cpp
blob879cad6349cb668505b1c020b914d65c47b6e098
1 point center(const point &p, const point &q, const point &r) {
2 double ax = q.x - p.x;
3 double ay = q.y - p.y;
4 double bx = r.x - p.x;
5 double by = r.y - p.y;
6 double d = ax*by - bx*ay;
8 if (cmp(d, 0) == 0) {
9 printf("Points are collinear!\n");
10 assert(false);
13 double cx = (q.x + p.x) / 2;
14 double cy = (q.y + p.y) / 2;
15 double dx = (r.x + p.x) / 2;
16 double dy = (r.y + p.y) / 2;
18 double t1 = bx*dx + by*dy;
19 double t2 = ax*cx + ay*cy;
21 double x = (by*t2 - ay*t1) / d;
22 double y = (ax*t1 - bx*t2) / d;
24 return point(x, y);